const login = async () => {
  if (!loginFormRef.value) return
  
  await loginFormRef.value.validate(async (valid) => {
    if (valid) {
      loading.value = true
      try {
        const res = await login(loginForm)
        // 将token保存到localStorage
        localStorage.setItem('token', res.data)
        
        // 登录成功后获取用户信息
        const userRes = await getUserInfo()
        localStorage.setItem('userInfo', JSON.stringify(userRes.data))
        
        ElMessage.success('登录成功')
        router.push('/home')
      } catch (error) {
        console.error('登录失败', error)
      } finally {
        loading.value = false
      }
    }
  })
} 